package com.atguigu.eduService.controller;

import com.atguigu.commonutils.R;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.vo.ChapterVo;
import com.atguigu.eduService.entity.vo.CourseQueryVo;
import com.atguigu.eduService.entity.vo.CourseWebVo;
import com.atguigu.eduService.entity.vo.TeacherQuery;
import com.atguigu.eduService.service.EduChapterService;
import com.atguigu.eduService.service.EduCourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "前台课程展示")
@RestController
@RequestMapping("/eduService/educhapter")
@CrossOrigin
public class CourseApiController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduChapterService chapterService;


    @ApiOperation(value = "分页查询课程列表")
    @PostMapping("getCourseApiPageVo/{current}/{limit}")
    public R getCourseApiPageVo(@PathVariable Long current,
                              @PathVariable Long limit,
                              @RequestBody CourseQueryVo courseQueryVo){
        Page<EduCourse> page=new Page<>(current,limit);
        Map<String,Object> map=eduCourseService.getCourseApiPageVo(page,courseQueryVo);
        return  R.ok().data(map);

    }

    @ApiOperation(value = "根据课程id查询课程信息")
    @PostMapping("getCourseWebInfo/{id}")
    public R getCourseWebInfo(@PathVariable  String id){
       CourseWebVo courseWebVo= eduCourseService.getCourseWebVo(id);
        List<ChapterVo> chapterVideoById = chapterService.getChapterVideoById(id);
        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoById",chapterVideoById);
    }
}

